from django.forms.fields import HiddenInput
from django.utils.safestring import mark_safe
from django.conf import settings


class ThumbnailInput(HiddenInput):
    # Sobrescribo el renderizado para mostrar una imagen
    def render(self, name, value, attrs=None):
        imgSource = settings.MEDIA_URL+'/djangollery/img/django-icon-256.png'
        if value is not None:
			imgSource=value	
        ret = '<img src="%s" id="id_img_%s" alt="Thumbnail"  />' % (imgSource,name)
        return mark_safe(ret + super(ThumbnailInput, self).render(name, value, attrs=attrs))

class LinkInput(HiddenInput):
	# Sobrescribo el renderizado para mostrar un enlace
	def render(self, name, value, attrs=None):
		href='javascript:void(0)'
		text='No definido'
		if value is not None:
			href = value
			text = value
		ret = '<a id="id_link_%s" href="%s" target="_blank" >%s</a>' % (name,href,text)
		return mark_safe(ret + super(LinkInput, self).render(name, value, attrs=attrs))
